package com.ruoyi.web.controller.config;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.entity.EnterpriseBasic;
import com.ruoyi.system.service.EnterpriseBasicService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 企业基础信息(EnterpriseBasic)表控制层
 * @since 2023-03-23 08:51:45
 */
@RestController
@RequestMapping("enterpriseBasic")
public class EnterpriseBasicController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private EnterpriseBasicService enterpriseBasicService;

    /**
     * 分页查询
     *
     * @param enterpriseBasic 筛选条件
     * @param pageRequest     分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<EnterpriseBasic>> queryByPage(EnterpriseBasic enterpriseBasic, PageRequest pageRequest) {
        return ResponseEntity.ok(this.enterpriseBasicService.queryByPage(enterpriseBasic, pageRequest));
    }

    @GetMapping("/list")
    public TableDataInfo queryByPage(EnterpriseBasic enterpriseBasic) {
        startPage();
        List<EnterpriseBasic> list = enterpriseBasicService.queryAll(enterpriseBasic);
        return getDataTable(list);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<EnterpriseBasic> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.enterpriseBasicService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param enterpriseBasic 实体
     * @return 新增结果
     */
    @PostMapping("add")
    @PreAuthorize("@ss.hasPermi('enterpriseBasic:add')")
    public ResponseEntity<EnterpriseBasic> add(@Validated @RequestBody EnterpriseBasic enterpriseBasic) {
        return ResponseEntity.ok(this.enterpriseBasicService.insert(enterpriseBasic));
    }

    /**
     * 编辑数据
     *
     * @param enterpriseBasic 实体
     * @return 编辑结果
     */
    @PutMapping("edit")
    @PreAuthorize("@ss.hasPermi('enterpriseBasic:edit')")
    public ResponseEntity<EnterpriseBasic> edit(@Validated @RequestBody EnterpriseBasic enterpriseBasic) {
        return ResponseEntity.ok(this.enterpriseBasicService.update(enterpriseBasic));
    }

    /**
     * 删除数据
     *
     * @param enterpriseBasic 主键
     * @return 删除是否成功
     */
    @DeleteMapping("delete")
    @PreAuthorize("@ss.hasPermi('enterpriseBasic:delete')")
    public ResponseEntity<Boolean> deleteById(@Validated @RequestBody EnterpriseBasic enterpriseBasic) {
        return ResponseEntity.ok(this.enterpriseBasicService.deleteById(enterpriseBasic.getId()));
    }

}

